<{include file="public/header.html"}>
		<div class="xinsu-right">
			<div class="xinsu-right-title" id="xinsu-zhishu"></div>
			<div class="xinsu-right-content">
				<form class="layui-form xinsu-form" action="" method="get">
					<div class="layui-form-item">
						<div class="layui-inline">
						    <label class="layui-form-label xinsu-form-label">查询日期</label>
						    <div class="layui-input-inline">
						        <input type="text" name="begin_time" id="begin_time" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this,max:laydate.now(-1)})" value="<{if 0 != $begin_time}><{$begin_time}><{/if}>">
						    </div>
						    <label class="layui-form-label xinsu-form-label2">至</label>
						    <div class="layui-input-inline">
						       <input type="text" name="end_time" id="end_time" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this,max:laydate.now(-1)})" value="<{if 0 != $end_time}><{$end_time}><{/if}>">
						    </div>
						</div>
						<button class="layui-btn xinsu-btn" >查询</button>
					</div>
				</form>
				<div class="layui-form">
					<table class="layui-table">
						<thead>
							<tr>
								<th>委托编号</th>
								<th>证券代码</th>
								<th>证券名称</th>
								<th>买 / 卖</th>
								<th>类型</th>
								<th>委托价格</th>
								<th>当前价</th>
								<th>委托数量</th>
								<th>委托时间</th>
								<th>成交/撤单时间</th>
								<th>状态</th>
								<th>操作</th>
							</tr> 
						</thead>
						<tbody>
							<{if empty($list) == false}>
							<{foreach $list as $val}>
							<tr id="xinsu-stock-<{$val.id}>"  class="xinsu-stock-status" data="<{$val.id}>">
								<td><{$val.id}></td>
								<td><{$val.stock_code}></td>
								<td><a class="xinsu-fontcolor-blue xinsu-stock-figure" href="javascript:;" data="<{$val.stock}>"><{$val.stock_name}></a></td>
								<{if $val.trust_type == 1}>
								<td class="xinsu-fontcolor-red">买</td>
								<{else}>
								<td class="xinsu-fontcolor-green">卖</td>
								<{/if}>
								<{if $val.bull_type == 1}>
								<td class="xinsu-fontcolor-red">融资↑</td>
								<{else}>
								<td class="xinsu-fontcolor-green">融券↓</td>
								<{/if}>
								<td><{$val.price}></td>	
								<td id="xinsu-stock-price-<{$val.id}>">--</td>
								<td><{$val.num}></td>
								<td><{date("Y-m-d H:i:s",$val["stock_trust_time"])}></td>	
								<td id="xinsu-stock-time-<{$val.id}>">--</td>	
								<td id="xinsu-stock-status-<{$val.id}>">--</td>
								<td><a href="javascript:;" id="xinsu-stock-manage-<{$val.id}>" class="xinsu-stock-cancel" data="<{$val.id}>" data-type="<{$val.trust_type}>">--</a></td>
							</tr>
							<{/foreach}>
							<{else}>
							<tr>
								<td colspan="12">暂无数据</td>
							</tr>
							<{/if}>
						</tbody>
					</table>
				</div>
				<div class="xinsu-page">
					<div class="xinsu-show">
						<{$page}>
					</div>
					<div class="xinsu-clear"></div>
				</div>
			</div>
		</div>
		<script>
			$(".xinsu-stock-cancel").click(function(){
				var url = "/stock/ajax_set_trust";
				var id = $(this).attr("data");
				var trust_type = $(this).attr("data-type");
				layer.confirm('您确定要撤销么？', {icon: 3}, function () {
					layer.closeAll();
					http_request_post(url, {id:id, trust_type:trust_type}, function(res) {
						layer.msg(res.msg, {icon: 1, time: 800}, function () {
							location.reload();
						});
					});
				});
			})
			<{if empty($list) == false}>
			$(function(){
				get_trust();
			})
			var stock = status = 0;
			//获取最新价格
			function get_trust() {
				if (stock >= 0 && system_holiday == 0) {
					var url = "/stock/ajax_get_trust";
					var data = "";
					$(".xinsu-stock-status").each(function(){
						var tmp = $(this).find("td").eq(0).html();
						if (tmp != undefined) {
							data += "," + tmp;
						}
					})
					http_request_post(url, {data:data}, function(result) {
						
						var res = result.data;
						$.each(res, function(key, val){
							if (val.status == 1) {
								//已完成
								$("#xinsu-stock-price-"+key).html("--");
								$("#xinsu-stock-status-"+key).html("已完成");
								$("#xinsu-stock-status-"+key).addClass("xinsu-fontcolor-red");
								$("#xinsu-stock-manage-"+key).html("--");
								$("#xinsu-stock-manage-"+key).removeClass("xinsu-stock-cancel");
								
							} else if (val.status == 2) {
								//已撤销
								$("#xinsu-stock-price-"+key).html("--");
								$("#xinsu-stock-status-"+key).html("已撤销");
								$("#xinsu-stock-manage-"+key).html("--");
								$("#xinsu-stock-manage-"+key).removeClass("xinsu-stock-cancel");
							} else {
								$("#xinsu-stock-price-"+key).html(val["price"]);
								$("#xinsu-stock-status-"+key).addClass("xinsu-fontcolor-green");
								$("#xinsu-stock-status-"+key).html("委托中");
								$("#xinsu-stock-manage-"+key).addClass("xinsu-stock-cancel");
								$("#xinsu-stock-manage-"+key).html("撤单");
								status = 1;
							}
							$("#xinsu-stock-time-"+key).html(val["stock_deal_time"]);
						})
					});
				}
				//防止无效提交
				if (status == 1) {
					stock = setTimeout("get_trust();", 1000);
				}
			}
			<{/if}>
		</script>
<{include file="public/footer.html"}>